package com.guli.edu.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guli.common.vo.R;
import com.guli.edu.entity.Course;
import com.guli.edu.entity.Teacher;
import com.guli.edu.service.CourseService;
import com.guli.edu.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author Frank
 * @since 2019-04-15
 */
@CrossOrigin
@Api(tags = "讲师模块", description = "前台讲师模块")
@RestController
@RequestMapping("/edu/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private CourseService courseService;

    @GetMapping
    @ApiOperation(value = "讲师列表")
    public R list(){
        List<Teacher> list = teacherService.list(null);


        return R.ok().data("items", list);
    }

    @GetMapping("{id}")
    @ApiOperation(value = "根据ID查询讲师")
    public R getById(
            @ApiParam(value = "讲师Id", name = "id", required = true)
            @PathVariable("id") String id
    ) {
        Teacher teacher = teacherService.getById(id);

        //根据讲师id查询这个讲师的课程列表
        List<Course> courseList = courseService.selectByTeacherId(id);

        return R.ok().data("teacher", teacher).data("courseList", courseList);
    }

    @GetMapping("{page}/{limit}")
    public R pageList(
            @ApiParam(value = "当前页码", name = "page", required = true)
            @PathVariable("page") long page,
            @ApiParam(value = "每页记录数", name = "limit" ,required = true)
            @PathVariable("limit") long limit
    ) {
        Page<Teacher> pageParam = new Page<>(page, limit);
        Map<String, Object> pageMap = teacherService.pageListWeb(pageParam);
        return R.ok().data(pageMap);
    }


        
        
        

}

